<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
class BgcmsOverviewBean {
	
    public function __construct() {
  	   //
    }
  		
    public function __destruct() {
  	   //
    }
    
   /*
    * Get latest added page.
    * @param $number the number page will be return
    * @return The list of page object. 
    * page object contain fields is same as defined in database  
    */  
    public static function get_latest_page($db, $number) {
        $strSQL = sprintf("SELECT page_id, page_name FROM %1\$s ORDER BY page_modified desc LIMIT $number", TBL_PAGE);
        return $db->get_results($strSQL);
    }
    
   /*
    * Get latest registered user.
    * @param $db is a ezSQL_mysql object
    * @param $number the number user will be return
    * @return The list of user object. 
    * User object contain fields is same as defined in database  
    */
	
	/*
    * Get total user.
	*/
    public static function count_all_user($db){
        $strSQL = sprintf("SELECT COUNT(user_id) as alluser FROM %1\$s ", TBL_USER);
        return $db->get_row($strSQL);
    }
	
	/*
    * Get total categories.
	*/
    public static function count_all_cat($db){
        $strSQL = sprintf("SELECT COUNT(cat_id) as allcat FROM %1\$s ", TBL_CATEGORY);
        return $db->get_row($strSQL);
    }
	
    /*
    * Get total pages.
	*/
	public static function count_all_page($db){
        $strSQL = sprintf("SELECT COUNT(page_id) as allpage FROM %1\$s ", TBL_PAGE);
        return $db->get_row($strSQL);
    }
	
    public static function get_latest_customer($db, $number) {
        $strSQL = sprintf("SELECT customer_id, customer_firstname, customer_lastname FROM %1\$s ORDER BY customer_registered desc LIMIT $number", TBL_CUSTOMER);
        return $db->get_results($strSQL);
    }
    
    public static function get_latest_project($db, $number) {
        $strSQL = sprintf("SELECT project_id, project_name FROM %1\$s ORDER BY project_create_date desc LIMIT $number", TBL_PROJECT);
        return $db->get_results($strSQL);
    }
	
	 public static function get_latest_user($db, $number){
        $strSQL = sprintf("SELECT user_id, user_name FROM %1\$s ORDER BY user_registered desc LIMIT $number", TBL_USER);
        return $db->get_results($strSQL);
    }

	public static function get_all_admin_menu($db) {
        $strSQL = sprintf("SELECT * FROM %s WHERE is_active=1 ORDER BY module_id", TBL_ADMIN_MENU);
        return $db->get_results($strSQL);
    }
}
?>